package com.yuhang.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yuhang.entity.HyBill;
import com.yuhang.entity.HyBillStream;
import com.yuhang.service.HyBillStreamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuhang
 * @since 2021-04-21
 */
@RestController
@RequestMapping("/hy-bill-stream")
public class HyBillStreamController {

    @Autowired
    private HyBillStreamService hyBillStreamService;

    @RequestMapping("/showAllBillStream")
    public Map<String,Object> showAllBillStream(@RequestParam(value = "page",defaultValue = "1")int pageNum,
                                         @RequestParam(value = "limit",defaultValue = "5")int pageSize){
        IPage<HyBillStream> page = hyBillStreamService.selectByPage(pageNum, pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("count",page.getTotal());
        map.put("data",page.getRecords());
        map.put("msg","");
        return map;
    }

    @RequestMapping("/addBillStream")
    public Map<String,Object> addBillStream(HyBillStream hyBillStream){
        hyBillStreamService.save(hyBillStream);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        return map;
    }

    @RequestMapping("/updateBillStream")
    public Map<String,Object> updateBillStream(HyBillStream hyBillStream){
        hyBillStreamService.updateById(hyBillStream);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        return map;
    }

    @RequestMapping("/deleteBillStream")
    public Map<String,Object> deleteBillStream(Integer id){
        hyBillStreamService.removeById(id);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        return map;
    }
}
